import { Module } from '@nestjs/common';
import { UploadService } from './upload.service';
import { UploadController } from './upload.controller';

import { MulterModule } from '@nestjs/platform-express'; // 导入MulterModule
import { diskStorage } from 'multer'; // 导入diskStorage
import { extname, join } from 'path'; // 导入extname

@Module({
  imports: [
    MulterModule.register({
      storage: diskStorage({
        destination: join(__dirname, '../images'), // 指定存储位置
        filename: (req, file, cb) => {
          // 指定文件名
          const fileName = `${Date.now()}-${extname(file.originalname)}`;
          cb(null, fileName);
        },
      }),
    }),
  ],
  controllers: [UploadController],
  providers: [UploadService],
})
export class UploadModule {}
